using MediatR;
using MeetingManagement.Application.Commands.Users.Login;
using Microsoft.AspNetCore.Mvc;

namespace MeetingManagement.WebApi.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class AuthController : ControllerBase
    {
        private readonly IMediator _mediator;
        public AuthController(IMediator mediator)
        {
            _mediator = mediator;
        }

        [HttpPost("login")]
        public async Task<IActionResult> Login([FromBody] LoginCommand command)
        {
            var result = await _mediator.Send(command);
            if (!result.Success) return Unauthorized(result);

            return Ok(result);
        }
    }
}
